<?php

declare(strict_types=1);

namespace App\Controller\Im;

use App\Controller\AbstractController;
use App\Request\Im\ImMessageLogRequest;
use App\Request\Im\ImUserListRequest;
use App\Request\Im\userInfoRequest;
use App\Service\Im\ImChatService;
use Psr\Http\Message\ResponseInterface;
use Hyperf\Di\Annotation\Inject;

class ImUserListController extends AbstractController
{

    /**
     * @Inject()
     * @var ImChatService
     */
    protected $imchatService;


    /**
     * 获取会话列表
     * @return mixed|ResponseInterface
     */
    public function messageList()
    {
        $data = $this->imchatService->messageList();
        return $this->response->success($data);
    }

    /**
     * 删除聊天
     * @param int $id
     * @return mixed|ResponseInterface
     */
    public function delete(int $id)
    {
        $ret = $this->imchatService->delMessage($id);
        return $this->response->success($ret);
    }


    /**
     * 保存聊天记录
     * @param ImUserListRequest $request
     * @return mixed|ResponseInterface
     */
    public function newMessage(ImUserListRequest $request)
    {
        $validator = $request->validated();
        $data = $this->imchatService->saveLastMessage($validator);
        return $this->response->success($data);
    }


    /**
     * 获取聊天历史
     * @param ImMessageLogRequest $request
     * @return mixed|ResponseInterface
     */
    public function messageLog(ImMessageLogRequest $request)
    {
        $validator = $request->validated();
        $data = $this->imchatService->messageLog($validator);
        return $this->response->success($data);
    }

    /**
     * 获取客服列表
     * @return mixed|ResponseInterface
     */
    public function getCustomerList()
    {
        $data = $this->imchatService->getCustomerList();
        return $this->response->success($data);
    }

    /**
     * 获取用户信息
     * @param userInfoRequest $request
     * @return mixed|ResponseInterface
     */
    public function UserInfo(userInfoRequest $request)
    {
        $validated = $request->validated();
        $data = $this->imchatService->UserData($validated['receive_user']);
        return $this->response->success($data);
    }

}
